<?php

class Admini_ManagedataController extends Uuch_ManageController{
      public function init() {
            parent::init();
            $this->appendCss('/css/home/warehouse.css');
            $this->appendCss('/admins/css/common.css');
            $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js')->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js')->appendScript('/js/uuch.js');
            $this->view->type = "finance";
            $this->view->countbillout = Application_Model_wayBillItem::getcountbill(Application_Model_wayBillItem::Interior_Outstorage,null);//今日发货
            $this->view->stype = 1;   
      }
      
      public function indexAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 1000;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $name = $this->getSafeParam("quick")?$this->getSafeParam("quick"):"陈广荣";
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            if($etime == ""){
                  $etime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
            }
            $arr = new Application_Model_Filter_StoreItemSearch();
            $arr->dateinbegin = $stime;
            $arr->dateinend =  $etime;
            $arr->operateName = $name;
            $arr->stus = Application_Model_StoreItem::Interior_Achieve;
            $objlist = Application_Model_StoreItem::getMyByFilter($arr, $pagesize, $pageindex);
            $list = Application_Model_StoreItem::getDaytimeCount($objlist['list']);
            $this->view->worker = Application_Model_adminuser::getAll();
            $this->view->wsum = $list[1]['wsum'];
            $this->view->sum = $list[1]['sum'];
            $this->view->resultlist = $list[0];
            $this->view->resultAll = $objlist;
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->name = $name;
            $this->view->stype = 34;
      }
      
      public function dumpindexAction() {
            $this->disableLayout();
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"):  date("Y-m-d");
            $name = $this->getSafeParam("quick");
            $arr = new Application_Model_Filter_StoreItemSearch();
            $arr->dateinbegin = $stime;
            $arr->dateinend =  $etime;
            $arr->operateName = $name;
            $arr->stus = Application_Model_StoreItem::Interior_Achieve;
            $objlist = Application_Model_StoreItem::getFilterAll($arr);
            $list = Application_Model_StoreItem::getDaytimeCount($objlist);
            $er = new Application_Model_Filter_GetdataDump;
            $er->title = "仓库入库数据";
            $er->printHeadArr = array("入库时间","入库重量","入库数量","操作人");
            $er->array = array($stime."至".$etime,$list[1]["wsum"],$list[1]["sum"],$name);
            $er->dumpDataTop();
            $er->dumpArrayData($list[0]);
            exit;
      }
    
      public function mdataAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 10;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"): date("Y-m-d");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            $Item = Application_Model_AgentPay::getFilter($stime,$etime, $pageindex, $pagesize);
            $objlist = $Item['list'];
            $this->view->objlist = $objlist ;
            $this->view->objAll = $Item;
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->stype = 31;
      }
      
      public function dumpmdataAction(){
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime");
            $objlist = Application_Model_AgentPay::getFilterAll($stime,$etime);
            $er = new Application_Model_Filter_GetdataDump;
            $er->title = "代支付数据";
            $er->printHeadArr = array("悠奇仓库号","金额","支付时间","类型","状态");
            $er->dumpDataTop();
            $er->printTypeArr = array("userstoreno","payMoney","dateProcee","TypeName","statuscaption");
            $er->dumpObjectData($objlist);
            exit;
      }

      public function userpaylogAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 10;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"): date("Y-m-d");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            $paybill = new Application_Model_Filter_PayBillSearch;
            $paybill->dateinbegin =$stime;
            $paybill->dateinend = $etime;
            $paybill->status = Application_Model_PayBill::PAY_STATUS_SUCCESS;
            $result = Application_Model_PayBill::getFilter($paybill, $pagesize, $pageindex);
            $resultlist = $result['list'];
            $this->view->resultlist = $resultlist ;
            $this->view->resultAll = $result;
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->status = Application_Model_PayBill::PAY_STATUS_SUCCESS;
            $this->view->stype = 32;
      }
      public function dumplogAction(){
//      if($this->_getParam("export") == "csv"){
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"): date("Y-m-d");
            $paybill = new Application_Model_Filter_PayBillSearch;
            $paybill->dateinbegin =$stime;
            $paybill->dateinend = $etime;
            $paybill->status = Application_Model_PayBill::PAY_STATUS_SUCCESS;
            $objlist =Application_Model_PayBill::getFilterAll($paybill);
            $er = new Application_Model_Filter_GetdataDump();
            $er->title = "用户支付记录";
            $er->printHeadArr = array("悠奇仓库号","时间","交易号","订单号","金额","美元","汇率","支付类型","类型");
            $er->printTypeArr = array(array("userinfo","Storeno"),"dateCreated","txnId","id","money","usmoney","rate","payname","typenames");
            $er->dumpDataTop();
            $er->dumpObjectData($objlist);
            exit;
//            foreach ($objlist as $Item) {
//                  echo iconv("UTF-8","GB2312",$Item->userinfo->Storeno).",";
//                  echo iconv("UTF-8","GB2312", $Item->dateCreated).",";
//                  echo iconv("UTF-8","GB2312",$Item->txnId).",";
//                  echo iconv("UTF-8", "GB2312", $Item->money).",";
//                  echo iconv("UTF-8", "GB2312", $Item->usmoney).",";
//                  echo iconv("UTF-8","GB2312",$Item->rate).",";
//                  echo iconv("UTF-8","GB2312",$Item->payname).",";
//                  echo iconv("UTF-8","GB2312",$Item->typenames).",";
//                  echo "\r\n";
//            }
//            die();
      }
      
      public function buyshopcountAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 10;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"): date("Y-m-d");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            $financialFilter = new Application_Model_Filter_FinancialSearch();
            $financialFilter->starttime = $stime;
            $financialFilter->endtime =  $etime;
            $financialFilter->objectType =  Application_Model_DomainobjectType::ObjectType_Order;
//            $financialFilter->state = Application_Model_UserAccountHistory::STATE_MONEY;
//            $financialFilter->operat = "手工";
            $financialItem = Application_Model_FinancialCheckItem::getFilter($financialFilter,$pagesize,$pageindex);
            $this->view->resultAll = $financialItem;
            $this->view->resultlist = $financialItem['list'];
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->stype = 33;
      }
      public function dumpshopcountAction(){
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"):"";
            $financialFilter = new Application_Model_Filter_FinancialSearch();
            $financialFilter->starttime = $stime;
            $financialFilter->endtime =  $etime;
            $financialFilter->objectType =  Application_Model_DomainobjectType::ObjectType_Order;
            $objlist =  Application_Model_FinancialCheckItem::getFilterAll($financialFilter);
            $er = new Application_Model_Filter_GetdataDump();
            $er->title = "后台手工操作";
            $er->printHeadArr = array("时间","代购订单号","淘宝订单号","变化金额","操作类型","仓库号","备注","操作人");
            $er->printTypeArr = array("DateCreated","ObjectId","orderTaobaoId","Money","MoneyTypeName",array("User","Storeno"),"Reason","applyName");
            $er->dumpDataTop();
            $er->dumpObjectData($objlist);
            exit;
      }
      
      public function orderdataAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 15;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            if($etime == ""){
                  $etime = date("Y-m-d");
            }
            $OrderSearch = new Application_Model_Filter_OrderSearch();
            $OrderSearch->starttime = $stime;
            $OrderSearch->endtime =  $etime;
            $OrderSearch->status = array(Application_Model_Order::STATUS_PAYING);
            $OrderSearch->seltime = "paidTime";
            $OrderSearch->isdelete = Application_Model_Order::Problem_Default;
            $objlist = Application_Model_Order::getByPages($OrderSearch, $pagesize, $pageindex);
            $this->view->resultlist = $objlist["list"];
            $this->view->resultAll = $objlist;
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->stype = 35;
      }
      
       public function dumporderdataAction(){
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"):date("Y-m-d");
            $OrderSearch = new Application_Model_Filter_OrderSearch();
            $OrderSearch->starttime = $stime;
            $OrderSearch->endtime =  $etime;
            $OrderSearch->status = array(Application_Model_Order::STATUS_PAYING);
            $OrderSearch->seltime = "paidTime";
            $OrderSearch->isdelete = Application_Model_Order::Problem_Default;
            $objlist =  Application_Model_Order::getdumporderdata($OrderSearch);
            $er = new Application_Model_Filter_GetdataDump();
            $er->title = "代购数据";
            $er->printHeadArr = array("付款时间","代购订单号","淘宝订单号","运费","预付款","购买账号","状态","退款金额");
            $er->printTypeArr = array("datePaid","id","procureNo","shipFee","productTotal","BuyidNoname","StatusName","moneygroup");
            $er->dumpDataTop();
            $er->dumpObjectData($objlist);
            exit;
      }
      
      public function waybillAction(){
            $page = $this->getSafeParam("pagesize");
            $pagesize = $page ? $page : 15;
            $pageindex = $this->getSafeParam('start');
            if (!$pageindex) {
                  $pageindex = 0;
            }
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime");
            if($stime == ""){
                  $stime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
            }
            if($etime == ""){
                  $etime = date("Y-m-d");
            }
            $WayBillSearch = new Application_Model_Filter_WayBillSearch();
            $WayBillSearch->starttime = $stime;
            $WayBillSearch->endtime =  $etime;
            $WayBillSearch->status = array(Application_Model_wayBillItem::STATUS_WaitPay);
            $objlist = Application_Model_wayBillItem::getBillAll($WayBillSearch, $pagesize, $pageindex);
            $this->view->resultlist = $objlist["list"];
            $this->view->resultAll = $objlist;
            $this->view->starttime = $stime;
            $this->view->endtime = $etime;
            $this->view->stype = 36;
      }
      
       public function dumpwaybillAction(){
            $stime = $this->getSafeParam("starttime");
            $etime = $this->getSafeParam("endtime")?$this->getSafeParam("endtime"):date("Y-m-d");
            $WayBillSearch = new Application_Model_Filter_WayBillSearch();
            $WayBillSearch->starttime = $stime;
            $WayBillSearch->endtime =  $etime;
            $WayBillSearch->status = array(Application_Model_wayBillItem::STATUS_WaitPay);
            $objlist = Application_Model_wayBillItem::getFillerAll($WayBillSearch);
            $getdataDump = new Application_Model_Filter_GetdataDump();
            $getdataDump->title = "国际运单数据";
            $getdataDump->printHeadArr = array("运单编号","付款时间","原单号","转单号","货代公司Id ","货代公司A(原货代公司)","货代公司B(修改后的货代公司)","国家","预估总金额","预估运费","真空费","木架加固费","保险费","报关费 ","优惠券","国内运费","最终收款","退款","状态","备注");
            $getdataDump->printTypeArr = array(
                "billno","datePaid","agentNo","logistics","agentId",
                array("AgentBy","name"),
                "agentnameByagentId",
                array("CityBy","name"),
                array("getFeeByType"=> Application_Model_FeeType::EstimateSum,"function"),
                array("getFeeByType"=>Application_Model_FeeType::EstimateShipFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::VacuumSeviceFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::WoodenFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::RatePremiumFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::ReportFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::CouponFee,"function"),
                array("getFeeByType"=>Application_Model_FeeType::CnShipFee,"function"),
                "lastMoney","refundMoney","ProblemType","interiorRemark"
            );
            $getdataDump->dumpDataTop();
            $getdataDump->dumpObjectData($objlist);
            exit;
      }
}
